<?php
require_once 'PHPUnit/Framework/TestCase.php';
require_once '../class_date_handler/DateHandler.class.php';

/**
 *
 */
class TesteDateHandler extends PHPUnit_Framework_TestCase{
    private $date;

    protected function setUp(){
        $this->date = new DateHandler();
    }

    public function testConvertDateMysqlVsPtBr(){
        $datePtBr = "11/02/1987";
        $result = $this->date->convertDateFormatMysql($datePtBr);
        $this->assertEquals("1987-02-11", $result);
    }

    public function testConvertDateMysqlVsPtBrMod1(){
        $datePtBr = "11/02-1987";
        $result = $this->date->convertDateFormatMysql($datePtBr);
        $this->assertEquals("Formato de data invalida", $result);
    }

    public function testConvertDateMysqlVsPtBrMod2(){
      $datePtBr = "11-02/1987";
      $result = $this->date->convertDateFormatMysql($datePtBr);
      $this->assertEquals("Formato de data invalida", $result);
    }

    public function testConvertDateMysqlVsPtBrMod3(){
      $datePtBr = "11/02--1987";
      $result = $this->date->convertDateFormatMysql($datePtBr);
      $this->assertEquals("Formato de data invalida", $result);
    }

    public function testConvertDateMysqlVsPtBrMod4(){
      $datePtBr = "11//2/1987";
      $result = $this->date->convertDateFormatMysql($datePtBr);
      $this->assertEquals("Formato de data invalida", $result);
    }

    public function testConvertDatePtBrVsMysqlMod1(){
      $dateMysql = "1987-02-11";
      $result = $this->date->convertDateFormatMysql($dateMysql);
      $this->assertEquals("11/02/1987", $result);
    }

    public function testCovertDatePtBrVsMysqlMod2(){
      $dateMysql = "1987--02-11";
      $result = $this->date->convertDateFormatMysql($dateMysql);
      $this->assertEquals("Formato de data invalida", $result);
    }

    public function testConvertDatePtBrVsMysqlMod3(){
      $dateMysql = "198--02-11";
      $result = $this->date->convertDateFormatMysql($dateMysql);
      $this->assertEquals("Formato de data invalida", $result);
    }

    public function testConvertDatePtBrVsMysqlMod4(){
      $dateMysql = "1987-02--1";
      $result = $this->date->convertDateFormatMysql($dateMysql);
      $this->assertEquals("Formato de data invalida", $result);
    }

    public function testCalcIdadeMod1(){
      $dateNiver = "11/02/1987";
      $result = $this->date->calcIdade($dateNiver);
      $this->assertEquals(23, $result);
    }

    public function testCalcIdadeMod2(){
      $dateNiver = "1987-02-11";
      $result = $this->date->calcIdade($dateNiver);
      $this->assertEquals(23, $result);
    }

    public function testCalcIdadeMod3(){
      $dateNiver = "19870211";
      $result = $this->date->calcIdade($dateNiver);
      $this->assertEquals("Formato de data invalida", $result);
    }

}
?>

